package com.dxysun.design.singleton;

public class LazyInnerClassSingleton
{
	//使用LazyInnerclassGeneral的时候，默认会先初始化内部类
	//如果没使用，则内部类是不加载的
	private LazyInnerClassSingleton()
	{
		// 防止反射创建多个实例
		if (LazyHolder.instance != null)
		{
			throw new RuntimeException("不允许创建多个实例");

		}
	}

	//每一个关键字都不是多余的，static是为了使单例的空间共李，保证这个方法不会被重写、董载
	public static final LazyInnerClassSingleton getInstance()
	{
		//在返回结果以前，一定会先加载内部类
		return LazyHolder.instance;
	}

	//默认不加载
	private static class LazyHolder
	{
		private static final LazyInnerClassSingleton instance = new LazyInnerClassSingleton();
	}

	public static void main(String[] args) {
		LazyInnerClassSingleton lazyInnerClassSingleton = LazyInnerClassSingleton.getInstance();

		LazyInnerClassSingleton lazyInnerClassSingleton1 = LazyInnerClassSingleton.getInstance();
		System.out.println("over");

	}
}
